package cn.edu.xmu.datamining.tangzk.mralgos.sssp;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

import cn.edu.xmu.datamining.tangzk.util.MyUtil;

public class GraphEdge implements Writable {

	private int nodeId;
	private int adjWeight;

	public GraphEdge() {
	}

	public GraphEdge(int id, int weight) {
		this.nodeId = id;
		this.adjWeight = weight;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		this.nodeId = in.readInt();
		this.adjWeight = in.readInt();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(this.nodeId);
		out.writeInt(this.adjWeight);
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof GraphEdge)) {
			return false;
		}
		GraphEdge edge = (GraphEdge) obj;
		if (this.nodeId != edge.nodeId) {
			return false;
		} else {
			return this.adjWeight == edge.adjWeight;
		}
	}

	@Override
	public int hashCode() {
		return this.nodeId * 17 + this.adjWeight;
	}

	@Override
	protected GraphEdge clone() {
		GraphEdge edge = new GraphEdge();
		edge.setNodeId(this.nodeId);
		edge.setAdjWeight(this.adjWeight);
		return edge;
	}

	@Override
	public String toString() {
		return this.nodeId + ":" + MyUtil.formatInt(this.adjWeight);
	}

	public int getAdjWeight() {
		return adjWeight;
	}

	public void setAdjWeight(int adjWeight) {
		this.adjWeight = adjWeight;
	}

	public int getNodeId() {
		return nodeId;
	}

	public void setNodeId(int nodeId) {
		this.nodeId = nodeId;
	}

}
